/*
    YmsgIRC - Program enabling YMSG chat clients to use IRC
    Copyright (C) 2011 Crash Daemonicus ( crashenator -at- gmail.com )

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common.h"
#include "YMSG_head.h"
#include "YMSG_field.h"
#include "YMSG_list.h"

/*
+Description:
	The most basic part of the YMSG protocol - a packet of information.
	Packets are formed by a 20-byte header followed by a dynamic length of field-data in Number/Value pairs where the number identifies the type of value.
	The header contains the length of the field-data. This field-data is representable in a String as it doesn't contain nulls.
	The header also contains the YMSG protocol Version, the type of packet which identifies what type of message it is (it's context), and it's status.

+About this implementation:
	This implements a packet as a Header object, and the field-data Contents (represented both as a string and a object containing Field objects)
	acquiring the total size of the packet as raw data and the acquisition of that raw data in a buffer are supported by methods.

	Note: YmsgItem is used as a field container for convenience reasons only.
	If you initialize with an Item, use a 0-typed one where applicable to prevent container-fields from being added during conversion. 
*/

class YmsgPacket{
	public:
		YmsgHead head;
		string content;
		YmsgItem contentObject;

		//YmsgPacket(                               int typ,int sta=1,int sid=0,int vid=0,int ver=16);
		//YmsgPacket(const YmsgHead& head2,const string& fields);
		//YmsgPacket(const string& fields,          int typ,int sta=1,int sid=0,int vid=0,int ver=16);
		YmsgPacket(const vector<YmsgField>& fields,int typ,int sta=1,int sid=0,int vid=0,int ver=16);
		YmsgPacket(const YmsgItem& fields,        int typ,int sta=1,int sid=0,int vid=0,int ver=16);

		int size();//calculates the total raw size of the packet in YMSG format.
		bool toBuf(char* buffer,int maxlen=65555);//write the raw packet in YMSG format to a buffer (65555 = 20 header + 65535 content)
		//char* toBuf();
		//
};
